<template>
  <view class="query_container">
    <view class="query_box">
      <van-field
        :value="value"
        placeholder="点击搜索您想找的商品名称"
        input-class="input"
        @blur="inputchange"
      />
     <view class="query_btn_box">
        <van-button custom-class="reset_btn" @tap="reset">重置</van-button>
        <van-button custom-class="query_btn" @tap="thequery">查询</van-button>
      </view>
    </view>

   <!-- 商品展示区域 -->
    <scroll-view
      :scroll-y="true"
      class="scroll-y"
      @scrolltolower="scroll_bottom"
    >
      <good-info :goodsList="goodList" v-if="goodList.length > 0"></good-info>
        <view class="no_order" v-if="goodList.length == 0">
        <image src="/static/index/no_good.png" mode="" style="width:200rpx;height:200rpx"/>
        <view>暂无相关宝贝</view>
      </view>
      <u-loadmore :status="status" :icon-type="iconType"
        :load-text="loadText"
        v-if="goodList.length != 0" />
    </scroll-view>
    <!-- 商品展示区域 -->
  </view>
</template>

<script>
import GoodInfo from '../components/good_info'
import { query_all_goods } from "../../utils/imapi";
export default {
  props: {},
  components: {
    GoodInfo
  },
  data() {
    return {
      value: "",
      option1: [
        { text: "全部", value: 0 },
        { text: "待付款", value: 1 },
        { text: "待发货", value: 2 },
        { text: "交易完成", value: 3 },
        { text: "售后", value: 4 },
        { text: "交易取消", value: 5 },
      ],
      goodList: [],
      value1: 0,
       queryparam: {
        goods_status: "3",
        page_index: 1,
        page_size: 4,
        title: "",
        load_spec:'1'
      },
       status: "nomore",
      iconType: "flower",
      loadText: {
        loadmore: "暂时没有了",
        loading: "努力加载中",
        nomore: "实在没有了",
      },
    };
  },
  computed: {},
  watch: {},
  onLoad() {
    this.query_all_goods()
  },
  onReady() {},
  onShow() {},
  methods: {
     async query_all_goods() {
      try {
        const data = await query_all_goods(this.queryparam);
        console.log(data);
        if (data.code == 0) {
          this.goodList = data.data;
          console.log(this.goodList);
        }
      } catch (error) {}
    },
    status_change(e) {
      console.log(e.detail);
    },
        inputchange(e) {
      console.log(e.detail);
      this.queryparam.title = e.detail.value;
    },
    reset() {
      this.queryparam = {
        goods_status: "",
        page_index: 1,
        page_size: 10,
        title: "",
        load_spec: "1",
      };
      this.query_all_goods();
    },
    thequery() {
      console.log(this.queryparam.title);
      this.query_all_goods();
    },
    async scroll_bottom() {
      console.log("触底了");
      this.status = "loading";
      this.queryparam.page_index++;
      try {
        const data = await query_all_goods(this.queryparam);
        this.$toast.loading("加载中");
        if (data.code == 0) {
          this.status = "loadmore";
          this.goodList.push(...data.data);
          console.log(data);
          if (data.data.length == 0) {
             this.status = "nomore";
            this.queryparam.page_index--;
            this.$toast("全部加载");
          }
        }
      } catch (error) {}
    },
  },
  onReachBottom() {},
  onHide() {},
};
</script>

<style scoped lang="scss" scoped>
.query_container {
   position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100vh;
  .query_box {
    width: 750upx;
    height: 220upx;
    background: #FE3772;
    padding: 32upx;
    /deep/ .van-cell {
      height: 68upx;
      background: #ffffff;
      border-radius: 38upx;
        display: flex;
      align-items: center;
      .input {
        height: 100%;
        font-size: 24upx;
         padding-top: 5rpx;
      }
    }
    .query_btn_box {
      margin-top: 20upx;
      display: flex;
      align-items: center;
      justify-content: space-between;
      /deep/ .van-dropdown-menu {
        width: 320upx;
        height: 68upx;
        background: #ffffff;
        border-radius: 34upx;
      }
      /deep/ .reset_btn {
        width: 320upx;
        height: 68upx;
        background: #ffffff;
        border-radius: 34upx;
        text-align: center;
        line-height: 68upx;
        font-size: 28upx;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #000000;
      }
      /deep/ .query_btn {
        width: 320upx;
        height: 68upx;
        background: #FE3772;
        border-radius: 34upx;
        text-align: center;
        line-height: 68upx;
        font-size: 28upx;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #fff;
        border: 1px solid #FFFFFF;
      }
    }
  }


}
.scroll-y {
  flex: 1;
  position: relative;
  overflow-y: scroll;
}
.no_order {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
}
</style>
